using System;
using System.Reflection;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Drawing.Design;
using System.Globalization;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PickGold.Controls
{
	[Designer(typeof(InputBoxDesigner))]
	[ToolboxData("<{0}:InputText runat=\"server\" />")]
	[ControlBuilder(typeof(InputBoxBuilder))]
	[DataBindingHandler("System.Web.UI.Design.TextDataBindingHandler, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
	[DefaultProperty("Value")]
	[SupportsEventValidation]
	[ValidationProperty("Value")]
	[ControlValueProperty("Value")]
	[DefaultEvent("TextChanged")]
	[ParseChildren(false)]//true, "Items"
	[PersistChildren(true)]
	[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	[AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	public class InputBox : ListControl, IPostBackDataHandler
    {
        private const string _textBoxKeyHandlerCall = "if (WebForm_TextBoxKeyHandler(event) == false) return false;";
        private const int DefaultMutliLineColumns = 20;
        private const int DefaultMutliLineRows = 2;

		public InputBox()
        {
		}

		#region text,password,textarea

        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
			string t;
			PropertyInfo pi;
            Page page = this.Page;
            if (page != null)
                page.VerifyRenderingInServerForm(this);
            string uniqueID = this.UniqueID;
            if (uniqueID != null)
                writer.AddAttribute(HtmlTextWriterAttribute.Name, uniqueID);
			InputBoxType inputType = this.InputType;
            switch (inputType)
            {
				case InputBoxType.SingleLine:
                    writer.AddAttribute(HtmlTextWriterAttribute.Type, "text");
                    if (((this.AutoCompleteType != System.Web.UI.WebControls.AutoCompleteType.None) && (this.Context != null)) && (this.Context.Request.Browser["supportsVCard"] == "true"))
                    {
                        if (this.AutoCompleteType == System.Web.UI.WebControls.AutoCompleteType.Disabled)
                        {
                            writer.AddAttribute(HtmlTextWriterAttribute.AutoComplete, "off");
                        }
                        else if (this.AutoCompleteType == System.Web.UI.WebControls.AutoCompleteType.Search)
                        {
                            writer.AddAttribute(HtmlTextWriterAttribute.VCardName, "search");
                        }
                        else if (this.AutoCompleteType == System.Web.UI.WebControls.AutoCompleteType.HomeCountryRegion)
                        {
                            writer.AddAttribute(HtmlTextWriterAttribute.VCardName, "HomeCountry");
                        }
                        else if (this.AutoCompleteType == System.Web.UI.WebControls.AutoCompleteType.BusinessCountryRegion)
                        {
                            writer.AddAttribute(HtmlTextWriterAttribute.VCardName, "BusinessCountry");
                        }
                        else
                        {
                            string str2 = Enum.Format(typeof(System.Web.UI.WebControls.AutoCompleteType), this.AutoCompleteType, "G");
                            if (str2.StartsWith("Business", StringComparison.Ordinal))
                            {
                                str2 = str2.Insert(8, ".");
                            }
                            else if (str2.StartsWith("Home", StringComparison.Ordinal))
                            {
                                str2 = str2.Insert(4, ".");
                            }
                            writer.AddAttribute(HtmlTextWriterAttribute.VCardName, "vCard." + str2);
                        }
                    }
                    string text = this.Text;
                    if (text.Length > 0)
                        writer.AddAttribute(HtmlTextWriterAttribute.Value, text);
                    break;
				case InputBoxType.MultiLine:
                    int rows = this.Rows;
                    int columns = this.Columns;
                    bool flag = false;
					pi = this.GetType().GetProperty("EnableLegacyRendering", BindingFlags.NonPublic | BindingFlags.Instance, null, typeof(bool), new Type[0], null);
                    if (!((bool)pi.GetValue(this, null)))//base.EnableLegacyRendering
                    {
                        if (rows == 0)
                            rows = 2;
                        if (columns == 0)
                            columns = 20;
                    }
                    if ((rows > 0) || flag)
                        writer.AddAttribute(HtmlTextWriterAttribute.Rows, rows.ToString(NumberFormatInfo.InvariantInfo));
                    if ((columns > 0) || flag)
                        writer.AddAttribute(HtmlTextWriterAttribute.Cols, columns.ToString(NumberFormatInfo.InvariantInfo));
                    if (!this.Wrap)
                        writer.AddAttribute(HtmlTextWriterAttribute.Wrap, "off");
                    goto Label_024E;
				case InputBoxType.Select:
					goto Label_End;
					//writer.AddAttribute(HtmlTextWriterAttribute.Type, "password");
                    //break;
				case InputBoxType.RadioList:
                    //writer.AddAttribute(HtmlTextWriterAttribute.Type, "password");
                    //break;
				case InputBoxType.CheckList:
                    //writer.AddAttribute(HtmlTextWriterAttribute.Type, "password");
                    //break;
                case InputBoxType.Radio:
                    t = this.Text;
                    if (t.Length > 0)
                        writer.AddAttribute(HtmlTextWriterAttribute.Value, t);
                    writer.AddAttribute(HtmlTextWriterAttribute.Type, "radio");
                    break;
                case InputBoxType.Check:
                    t = this.Text;
                    if (t.Length > 0)
                        writer.AddAttribute(HtmlTextWriterAttribute.Value, t);
                    writer.AddAttribute(HtmlTextWriterAttribute.Type, "checkbox");
                    break;
                case InputBoxType.Image:
                    writer.AddAttribute(HtmlTextWriterAttribute.Type, "image");
                    break;
                case InputBoxType.File:
                    writer.AddAttribute(HtmlTextWriterAttribute.Type, "file");
                    break;
                case InputBoxType.Button:
                    t = this.Text;
                    if (string.IsNullOrEmpty(t))
						t = this.ID;
                    writer.AddAttribute(HtmlTextWriterAttribute.Value, t);
                    writer.AddAttribute(HtmlTextWriterAttribute.Type, "button");
                    break;
                case InputBoxType.Reset:
                    t = this.Text;
                    if (string.IsNullOrEmpty(t))
						t = this.ID;
                    writer.AddAttribute(HtmlTextWriterAttribute.Value, t);
                    writer.AddAttribute(HtmlTextWriterAttribute.Type, "reset");
                    break;
                case InputBoxType.Submit:
                    t = this.Text;
                    if (string.IsNullOrEmpty(t))
						t = this.ID;
                    writer.AddAttribute(HtmlTextWriterAttribute.Value, t);
                    writer.AddAttribute(HtmlTextWriterAttribute.Type, "submit");
                    break;
                case InputBoxType.Password:
                    writer.AddAttribute(HtmlTextWriterAttribute.Type, "password");
                    break;
                case InputBoxType.Hidden:
                    t = this.Text;
                    if (t.Length > 0)
                        writer.AddAttribute(HtmlTextWriterAttribute.Value, t);
                    writer.AddAttribute(HtmlTextWriterAttribute.Type, "hidden");
                    break;
            }
            int maxLength = this.MaxLength;
            if (maxLength > 0)
                writer.AddAttribute(HtmlTextWriterAttribute.Maxlength, maxLength.ToString(NumberFormatInfo.InvariantInfo));
            maxLength = this.Columns;
            if (maxLength > 0)
                writer.AddAttribute(HtmlTextWriterAttribute.Size, maxLength.ToString(NumberFormatInfo.InvariantInfo));
Label_024E:
            if (this.ReadOnly)
                writer.AddAttribute(HtmlTextWriterAttribute.ReadOnly, "readonly");
			if (page == null)
				pi = null;
			else
				pi = page.GetType().GetProperty("ClientSupportsJavaScript", BindingFlags.NonPublic | BindingFlags.Instance, null, typeof(bool), new Type[0], null);
            if (this.AutoPostBack && pi != null && ((bool)pi.GetValue(page, null)))//(page != null)) && page.ClientSupportsJavaScript
            {
                string str4 = null;
                if (base.HasAttributes)
                {
                    str4 = base.Attributes["onchange"];
                    if (str4 != null)
                    {
                        str4 = Util.EnsureEndWithSemiColon(str4);
                        base.Attributes.Remove("onchange");
                    }
                }
                PostBackOptions options = new PostBackOptions(this, string.Empty);
                if (this.CausesValidation)
                {
                    options.PerformValidation = true;
                    options.ValidationGroup = this.ValidationGroup;
                }
                if (page.Form != null)
                {
                    options.AutoPostBack = true;
                }
                str4 = Util.MergeScript(str4, page.ClientScript.GetPostBackEventReference(options, true));
                writer.AddAttribute(HtmlTextWriterAttribute.Onchange, str4);
				if (inputType != InputBoxType.MultiLine && inputType != InputBoxType.Hidden)
                {
                    string str5 = "if (WebForm_TextBoxKeyHandler(event) == false) return false;";
                    if (base.HasAttributes)
                    {
                        string str6 = base.Attributes["onkeypress"];
                        if (str6 != null)
                        {
                            str5 = str5 + str6;
                            base.Attributes.Remove("onkeypress");
                        }
                    }
                    writer.AddAttribute("onkeypress", str5);
                }
				pi = this.GetType().GetProperty("EnableLegacyRendering", BindingFlags.NonPublic | BindingFlags.Instance, null, typeof(bool), new Type[0], null);
                if ((bool)pi.GetValue(this, null))//base.EnableLegacyRendering
                    writer.AddAttribute("language", "javascript", false);
            }
            else if (page != null)
            {
                page.ClientScript.RegisterForEventValidation(this.UniqueID, string.Empty);
            }
            if (this.Enabled && !base.IsEnabled)
                writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled");
Label_End:
            base.AddAttributesToRender(writer);
        }

        protected override void AddParsedSubObject(object obj)
        {
			ListItem listItem = obj as ListItem;
			if (listItem != null)
			{
				base.AddParsedSubObject(listItem);
				base.Items.Add(listItem);
				return;
			}

			if (!(obj is LiteralControl))
				return;

			string[] rows, item;
			string t = ((LiteralControl) obj).Text;
			InputBoxType type = this.InputType;
			if (type == InputBoxType.Select || type == InputBoxType.RadioList || type == InputBoxType.CheckList)
			{
				rows = t.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
				for (int i = 0; i < rows.Length; i++)
				{
					rows[i] = rows[i].Trim();
					item = rows[i].Split(new char[] { '\t' }, 2, StringSplitOptions.RemoveEmptyEntries);
					if (item.Length == 0)
						listItem = null;
					else if (item.Length == 1)
						listItem = new ListItem(item[0].Trim());
					else
						listItem = new ListItem(item[1].Trim(), item[0].Trim());
					if (listItem != null)
					{
						base.AddParsedSubObject(listItem);
						base.Items.Add(listItem);
					}
				}
				return;
			}

			this.Text = t;
        }

		protected virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection)
		{
			MethodInfo mi;
			InputBoxType type = this.InputType;
			if (type == InputBoxType.Select || type == InputBoxType.RadioList || type == InputBoxType.CheckList)
			{
				string[] vals = postCollection.GetValues(postDataKey);
				this.EnsureDataBound();
				if (vals == null)
					return false;

				mi = this.GetType().GetMethod("ValidateEvent", BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(string), typeof(string) }, null);
				mi.Invoke(this, new object[] { postDataKey, vals[0] });
				//base.ValidateEvent(postDataKey, vals[0]);
				mi = this.Items.GetType().GetMethod("FindByValueInternal", BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(string), typeof(bool) }, null);
				int selectedIndex = (int)mi.Invoke(this.Items, new object[] { vals[0], false });
				//int selectedIndex = this.Items.FindByValueInternal(vals[0], false);
				if (this.SelectedIndex == selectedIndex)
					return false;

				base.SetPostDataSelection(selectedIndex);
				return true;
			}

			mi = this.GetType().GetMethod("ValidateEvent", BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(string) }, null);
			mi.Invoke(this, new object[] { postDataKey });
			//base.ValidateEvent(postDataKey);
			string val = postCollection[postDataKey];
			if (this.ReadOnly || this.Text.Equals(val, StringComparison.Ordinal))
				return false;

			this.Text = val;
			return true;
		}

		protected override void OnPreRender(EventArgs e)
		{
			base.OnPreRender(e);
			//InputBoxType type = this.InputType;
			//if (type == InputBoxType.Select || type == InputBoxType.RadioList || type == InputBoxType.CheckList)
			//    return;

			//Page page = this.Page;
			//if (page == null || !base.IsEnabled)
			//    return;

			//MethodInfo mi;
			//if (!this.SaveTextViewState)
			//{
			//    mi = page.GetType().GetMethod("RegisterEnabledControl", BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(Control) }, null);
			//    mi.Invoke(page, new object[] { this });
			//    //page.RegisterEnabledControl(this);
			//}
			//if (this.AutoPostBack)
			//{
			//    mi = page.GetType().GetMethod("RegisterWebFormsScript", BindingFlags.NonPublic | BindingFlags.Instance);
			//    mi.Invoke(page, null);
			//    //page.RegisterWebFormsScript();
			//    mi = page.GetType().GetMethod("RegisterPostBackScript", BindingFlags.NonPublic | BindingFlags.Instance);
			//    mi.Invoke(page, null);
			//    //page.RegisterPostBackScript();
			//    mi = page.GetType().GetMethod("RegisterFocusScript", BindingFlags.NonPublic | BindingFlags.Instance);
			//    mi.Invoke(page, null);
			//    //page.RegisterFocusScript();
			//}
		}

        protected virtual void RaisePostDataChangedEvent()
        {
			PropertyInfo pi = this.Page.GetType().GetProperty("IsPostBackEventControlRegistered", BindingFlags.NonPublic | BindingFlags.Instance, null, typeof(bool), new Type[0], null);
            if (this.AutoPostBack && !((bool)pi.GetValue(this.Page, null)))//this.Page.IsPostBackEventControlRegistered
            {
				pi = this.Page.GetType().GetProperty("AutoPostBackControl", BindingFlags.NonPublic | BindingFlags.Instance, null, typeof(Control), new Type[0], null);
				pi.SetValue(this.Page, this, null);
                //this.Page.AutoPostBackControl = this;
                if (this.CausesValidation)
                    this.Page.Validate(this.ValidationGroup);
            }
            this.OnTextChanged(EventArgs.Empty);
			this.OnSelectedIndexChanged(EventArgs.Empty);
        }

		protected override void Render(HtmlTextWriter writer)
		{
			InputBoxType type = this.InputType;
			if (type == InputBoxType.Select || type == InputBoxType.RadioList || type == InputBoxType.CheckList)
			{
				base.Render(writer);
				return;
			}

			if (this.TextAlign == TextAlign.Left)
			{
				this.RenderLabel(writer);
				this.RenderInput(writer);
			}
			else
			{
				this.RenderInput(writer);
				this.RenderLabel(writer);
			}
		}

		private void RenderInput(HtmlTextWriter writer)
        {
			InputBoxType type = this.InputType;
            this.RenderBeginTag(writer);
			if (type == InputBoxType.MultiLine)
                HttpUtility.HtmlEncode(this.Text, writer);
            this.RenderEndTag(writer);
        }

		private void RenderLabel(HtmlTextWriter writer)
		{
			InputBoxType type = this.InputType;
			string label = this.Label;
			if(string.IsNullOrEmpty(label))
				return;

			if (type != InputBoxType.Radio && type != InputBoxType.Check)
				return;

			writer.AddAttribute(HtmlTextWriterAttribute.For, this.UniqueID);
			//if ((this._labelAttributes != null) && (this._labelAttributes.Count != 0))
			//	this._labelAttributes.AddAttributes(writer);
			writer.RenderBeginTag(HtmlTextWriterTag.Label);
			writer.Write(label);
			writer.RenderEndTag();
		}

        protected override object SaveViewState()
        {
            if (!this.SaveTextViewState)
                this.ViewState.SetItemDirty("Text", false);
            return base.SaveViewState();
        }

		[Category("Behavior")]
		[Description("InputBox AutoCompleteType")]
        [DefaultValue(0)]
		[Themeable(false)]
        public virtual System.Web.UI.WebControls.AutoCompleteType AutoCompleteType
        {
            get
            {
                object obj2 = this.ViewState["AutoCompleteType"];
                if (obj2 != null)
                    return (System.Web.UI.WebControls.AutoCompleteType) obj2;

				return System.Web.UI.WebControls.AutoCompleteType.None;
            }
            set
            {
                if ((value < System.Web.UI.WebControls.AutoCompleteType.None) || (value > System.Web.UI.WebControls.AutoCompleteType.Search))
                    throw new ArgumentOutOfRangeException("value");

				this.ViewState["AutoCompleteType"] = value;
            }
        }

		[Category("Behavior")]
        [Description("InputBox AutoPostBack")]
		[DefaultValue(false)]
		[Themeable(false)]
        public virtual bool AutoPostBack
        {
            get
            {
                object obj2 = this.ViewState["AutoPostBack"];
                return ((obj2 != null) && ((bool) obj2));
            }
            set
            {
                this.ViewState["AutoPostBack"] = value;
            }
        }

        [Category("Behavior")]
		[Description("AutoPostBackControl CausesValidation")]
		[DefaultValue(false)]
		[Themeable(false)]
        public virtual bool CausesValidation
        {
            get
            {
                object obj2 = this.ViewState["CausesValidation"];
                return ((obj2 != null) && ((bool) obj2));
            }
            set
            {
                this.ViewState["CausesValidation"] = value;
            }
        }

		[Category("Appearance")]
		[Description("InputBox Columns")]
        [DefaultValue(0)]
        public virtual int Columns
        {
            get
            {
                object obj2 = this.ViewState["Columns"];
                if (obj2 != null)
                    return (int) obj2;

				return 0;
            }
            set
            {
                if (value < 0)
                    throw new ArgumentOutOfRangeException("Input Box Invalid Columns");

				this.ViewState["Columns"] = value;
            }
        }

		[Category("Behavior")]
		[Description("InputBox MaxLength")]
        [DefaultValue(0)]
		[Themeable(false)]
        public virtual int MaxLength
        {
			get
			{
				object obj2 = this.ViewState["MaxLength"];
				if (obj2 != null)
					return (int)obj2;

				return 0;
			}
            set
            {
                if (value < 0)
                    throw new ArgumentOutOfRangeException("value");

					this.ViewState["MaxLength"] = value;
            }
        }

		[Category("Behavior")]
		[Description("InputBox ReadOnly")]
        [DefaultValue(false)]
		[Bindable(true)]
		[Themeable(false)]
        public virtual bool ReadOnly
        {
            get
            {
                object obj2 = this.ViewState["ReadOnly"];
                return ((obj2 != null) && ((bool) obj2));
            }
            set
            {
                this.ViewState["ReadOnly"] = value;
            }
        }

		[Category("Behavior")]
        [Description("InputBox Rows")]
		[DefaultValue(0)]
		[Themeable(false)]
        public virtual int Rows
        {
            get
            {
                object obj2 = this.ViewState["Rows"];
                if (obj2 != null)
                    return (int) obj2;

				return 0;
            }
            set
            {
                if (value < 0)
                    throw new ArgumentOutOfRangeException("Input Box Invalid Rows");

				this.ViewState["Rows"] = value;
            }
        }

        private bool SaveTextViewState
        {
            get
            {
				//if (this.InputType == InputBoxType.Password)
				//    return false;

				//if (base.Events[EventTextChanged] == null && base.IsEnabled && this.Visible && !this.ReadOnly && base.GetType() == typeof(InputBox))
				//    return false;

				//return true;
				return false;
            }
        }

        protected override HtmlTextWriterTag TagKey
        {
            get
            {
				InputBoxType type = this.InputType;
                if (type == InputBoxType.MultiLine)
                    return HtmlTextWriterTag.Textarea;

				if (type == InputBoxType.Select)
					return HtmlTextWriterTag.Select;

				if (type == InputBoxType.RadioList || type == InputBoxType.CheckList)
					return HtmlTextWriterTag.Unknown;

                return HtmlTextWriterTag.Input;
            }
        }

		[Category("Appearance")]
		[Description("InputBox Value")]
		[Localizable(true)]
		[Editor("System.ComponentModel.Design.MultilineStringEditor,System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
		[Bindable(true, BindingDirection.TwoWay)]
		[DefaultValue("")]
		[PersistenceMode(PersistenceMode.EncodedInnerDefaultProperty)]
		public virtual string Value
		{
			get
			{
				string str = (string)this.ViewState["Value"];
				if (str != null)
					return str;

				return string.Empty;
			}
			set
			{
				this.ViewState["Value"] = value;
			}
		}

		[Category("Appearance")]
		[Description("InputBox Text")]
		[Localizable(true)]
		[Editor("System.ComponentModel.Design.MultilineStringEditor,System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
		[Bindable(true, BindingDirection.TwoWay)]
		[DefaultValue("")]
		[PersistenceMode(PersistenceMode.EncodedInnerDefaultProperty)]
		public override string Text
		{
			get
			{
				InputBoxType type = this.InputType;
				if (type == InputBoxType.Select || type == InputBoxType.RadioList || type == InputBoxType.CheckList)
					return base.Text;

				return this.Value;
			}
			set
			{
				InputBoxType type = this.InputType;
				if (type == InputBoxType.Select || type == InputBoxType.RadioList || type == InputBoxType.CheckList)
				{
					base.Text = value;
					return;
				}

				this.Value = value;
			}
		}

		[Category("Appearance")]
		[Description("InputBox Label")]
		[Localizable(true)]
		[Editor("System.ComponentModel.Design.MultilineStringEditor,System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
		[Bindable(true, BindingDirection.TwoWay)]
		[DefaultValue("")]
		[PersistenceMode(PersistenceMode.EncodedInnerDefaultProperty)]
		public virtual string Label
		{
			get
			{
				string str = (string)this.ViewState["Label"];
				if (str != null)
					return str;

				return string.Empty;
			}
			set
			{
				this.ViewState["Label"] = value;
			}
		}

		[Category("Behavior")]
		[Description("InputBox InputType")]
        [DefaultValue(0)]
		[Themeable(false)]
        public virtual InputBoxType InputType
        {
            get
            {
                object obj2 = this.ViewState["Type"];
                if (obj2 != null)
					return (InputBoxType)obj2;

				return InputBoxType.SingleLine;
            }
            set
            {
				if ((value < InputBoxType.SingleLine) || (value > InputBoxType.Hidden))
                    throw new ArgumentOutOfRangeException("value");

				this.ViewState["Type"] = value;
            }
        }

		[Category("Behavior")]
		[Description("PostBackControl ValidationGroup")]
        [Themeable(false)]
		[DefaultValue("")]
        public virtual string ValidationGroup
        {
            get
            {
                string str = (string) this.ViewState["ValidationGroup"];
                if (str != null)
                    return str;

				return string.Empty;
            }
            set
            {
                this.ViewState["ValidationGroup"] = value;
            }
        }

		[Category("Layout")]
		[Description("InputBox Wrap")]
        [DefaultValue(true)]
        public virtual bool Wrap
        {
            get
            {
                object obj2 = this.ViewState["Wrap"];
                if (obj2 != null)
                    return (bool) obj2;

				return true;
            }
            set
            {
                this.ViewState["Wrap"] = value;
            }
        }

		#endregion

		#region select

		protected override ControlCollection CreateControlCollection()
		{
			return new EmptyControlCollection(this);
		}

		protected override void VerifyMultiSelect()
		{
			throw new HttpException("Cant Multiselect");
		}

		[Category("Behavior")]
		[Description("WebControl SelectedIndex")]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		[DefaultValue(0)]
		public override int SelectedIndex
		{
			get
			{
				int selectedIndex = base.SelectedIndex;
				if (selectedIndex < 0 && this.Items.Count > 0)
				{
					this.Items[0].Selected = true;
					selectedIndex = 0;
				}
				return selectedIndex;
			}
			set
			{
				base.SelectedIndex = value;
			}
		}

		public override string SelectedValue
		{
			get
			{
				return base.SelectedValue;
			}
			set
			{
				try
				{
					base.SelectedValue = value;
				}
				catch
				{
					this.Items.Add(new ListItem(value));
					base.SelectedValue = value;
				}
			}
		}

		#endregion

        [DefaultValue(1)]
		public virtual TextAlign TextAlign
		{
			set
			{
				this.ViewState["TextAlign"] = value;
			}
			get
			{
				object o = this.ViewState["TextAlign"];
				if (o == null)
					return TextAlign.Left;

				return (TextAlign)o;
			}
		}

		bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection)
		{
			return this.LoadPostData(postDataKey, postCollection);
		}

		void IPostBackDataHandler.RaisePostDataChangedEvent()
		{
			this.RaisePostDataChangedEvent();
		}

	}
}

